// Chromanova!!!

/*
 * Benjamin Hitov
 * Ricky Mondello
 * Brooke Evans
 * Daniel Millstein
 *
 * DynamicBall.java - An abstract for ball types that will be able to move,
 *      currently only implemented by Player.java
 */

package chromafinal;

import java.awt.*;
/**
 *
 * @author Benjamin
 */
public abstract class DynamicBall {

    protected double xl, yl, xv, yv, xa, ya;
    protected int mass, size, num, cnum;
    Color color;

    public DynamicBall(double x, double y, int m, int size0, int num0, Color color0)
    {
        xl = x; yl = y; xv = 0; yv = 0; xa = 0; ya = 0;
        mass = m;
        size = size0;
        color = color0;
        num = num0;
        cnum = 1;
    }

    public void move(int period)
    {
        double mtime = period/1000.0;

        xv+= xa * mtime;    yv+= ya * mtime;
        xl+= xv * mtime;    yl+= yv * mtime;
        xa = 0;             ya = 0;

    }

    public void push(double x, double y)
    {
        xa += x;
        ya += y;
    }

    public void push(DynamicBall b)
    {
        new Ball(this,0,mass*cnum).pushBall(b, 0);
    }

    public void pushPlayer(Player p)
    {
        new Ball(this,0,mass).pushPlayer(p);
    }

    public double dist(DynamicBall b)
    {
        return Math.pow(Math.pow(xl-b.xl,2) + Math.pow(yl-b.yl,2),0.5);
    }

    public void draw(Graphics g)
    {
        g.setColor(color);
        g.fillOval((int) (xl-size/2), (int) (yl-size/2), size, size);
    }

}
